home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / dev / lang / Python151_Src.lha / Python1.5_Source / Amiga / fhopen.c < prev    next >
C/C++ Source or Header  |  1994-09-30  |  2KB  |  84 lines

  1. RCS_ID_C="$Id: fhopen.c,v 4.1 1994/09/29 23:09:02 jraja Exp $";
  2. /*
  3.  *      fhopen.c - open level 1 file from an AmigaDOS file handle (SAS/C)
  4.  *
  5.  *      Copyright © 1994 AmiTCP/IP Group, 
  6.  *                       Network Solutions Development Inc.
  7.  *                       All rights reserved.
  8.  */
  9.  
  10. #include <ios1.h>
  11. #include <fcntl.h>
  12. #include <stdlib.h>
  13. #include <dos.h>
  14. #include <string.h>
  15. #include <errno.h>
  16. #include <dos/dos.h>
  17. #include <proto/dos.h>
  18.  
  19. #include <bsdsocket.h>
  20.  
  21. extern int (*__closefunc)(int);
  22.  
  23. int
  24. fhopen(long file, int mode)
  25. {
  26.   struct UFB *ufb;
  27.   int         fd;
  28.   int         flags;
  29.  
  30.   /*
  31.    * Set up __closefunc (which is used at cleanup)
  32.    */
  33.   __closefunc = __close;
  34.   /*
  35.    * Check for the break signals
  36.    */
  37.   __chkabort();
  38.   /*
  39.    * find first free ufb
  40.    */
  41.   ufb = __allocufb(&fd);
  42.   if (ufb == NULL)
  43.     return -1; /* errno is set by the __allocufb() */
  44.  
  45.   /*
  46.    * Translate mode to ufb flags
  47.    */
  48.   switch (mode & (O_WRONLY | O_RDWR)) {
  49.   case O_RDONLY:
  50.     if (mode & (O_APPEND | O_CREAT | O_TRUNC | O_EXCL)) {
  51.       errno = EINVAL;
  52.       return -1;
  53.     }
  54.     flags = UFB_RA;
  55.     break;
  56.   case O_WRONLY:
  57.     flags = UFB_WA;
  58.     break;
  59.   case O_RDWR:
  60.     flags = UFB_RA | UFB_WA;
  61.     break;
  62.   default:
  63.     errno = EINVAL;
  64.     return -1;
  65.   }
  66.   if (mode & O_APPEND)
  67.     flags |= UFB_APP;
  68.   if (mode & O_XLATE)
  69.     flags |= UFB_XLAT;
  70.   /*
  71.    * All done!
  72.    */
  73.   ufb->ufbflg = flags;
  74.   ufb->ufbfh = (long)file;
  75.   ufb->ufbfn = NULL;
  76.  
  77. #if 0
  78.   if (Dup2Socket(-1, fd) < 0)    /* mark the fd as used in the AmiTCP's dTable */
  79.     perror("Dup2Socket failed on " __FILE__);
  80. #endif
  81.  
  82.   return fd;
  83. }
  84.